//
//  NvPreviewDlgViewController.m
//  NvSellerShow
//
//  Created by Meicam on 2017/2/14.
//  Copyright © 2017年 Meicam. All rights reserved.
//

#import "NvPreviewDlgViewController.h"
#import "NvWindowPlayer.h"

@interface NvPreviewDlgViewController () 
@property (nonatomic, strong) NvWindowPlayer *player;
@end

@implementation NvPreviewDlgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.player = [NvWindowPlayer instancePlayer];
    
    if(self.timeline != nil) {
        self.player.playStart = self.playStart;
        self.player.playEnd = self.playEnd;
        self.player.timeline = self.timeline;
        [self.player connectTimelineAndLiveWindow];
    } else {
        if(self.model) {
            self.player.model = self.model;
        }
    }
    self.player.frame = CGRectZero;
    if (self.editmode == NvSSVideoCreateScaleSquare) {//1X1
        self.player.size_LL = CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH);
    } else if (self.editmode == NvSSVideoCreateScaleHorizontal) {//16*9
        self.player.size_LL = CGSizeMake(SCREEN_WIDTH, 9.0/16.0*SCREEN_WIDTH);
    } else {//9:16
        self.player.size_LL = CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH);
    }
    self.player.createMode = self.editmode;
    self.player.center = self.view.center;
    [self.view addSubview:self.player];
    
    [self initNavigationBarView];
}

- (void)initNavigationBarView {
    self.view.backgroundColor = UIColorHexRGB(@"#F5F5F5");
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [backBtn setBackgroundImage:[UIImage imageFromBundle:@"back_icon"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    
    self.title = @"视频预览";
}


- (void)back:(id)sender {
    [self.streamingContext connectTimeline:self.timeline withLiveWindow:nil];
    self.streamingContext.delegate = nil;
    [self.navigationController popViewControllerAnimated:YES];
}

//MARK: Dealloc
- (void)dealloc
{
    [self.player clear];
    self.player=nil;
    NSLog(@"\n\n\n\n\n\n------priviewDlg---------\n\n\n\n\n\n");
}

@end
